# -*- coding: utf-8 -*-
import functools
import logging
import traceback

from app.ticket_manage.error_notice import error_notice

logger = logging.getLogger('django')


def auto_log(func):
    """
    auto write log decorator
    :param func:
    :return:
    """
    @functools.wraps(func)
    def _deco(*args, **kwargs):
        try:
            real_func = func(*args, **kwargs)
            return real_func
        except Exception as e:
            error = '{}方法错误auto_log:{}'.format(func.__name__, traceback.format_exc())
            error_notice(error_msg=error)
            logger.error(error)
            return False, e.__str__()
    return _deco
